class DoYunSuan():
    num = 100

    # 加
    def mySum(self, a, b):
        try:
            if isinstance(a,(int,float)) and isinstance(b,(int,float)):
                jia = a + b
                if isinstance(a,(float)) or isinstance(b,(float)):
                    jia = round(jia,2)     # 四舍五入,保留两位小数
            else:
                return '您是非法输入'
        except Exception as e:
            print(f'处理加法时发生了异常,异常信息是{e}')
        else:
            print('没有异常')
            return jia
        finally:
            print('不确定是否发生了异常')


    # 减
    def myJian(self, a, b):
        try:
            if isinstance(a, (int, float)) and isinstance(b, (int, float)):
                jian = a - b
                if isinstance(a,(float)) or isinstance(b,(float)):
                    jian = round(jian,2)     # 四舍五入,保留两位小数
            else:
                return '您是非法输入'
        except Exception as e:
                print(f'处理加法时发生了异常,异常信息是{e}')
        else:
            print('没有异常')
            return jian
        finally:
            print('不确定是否发生了异常')


    # 乘
    def myCheng(self, a, b):
        try:
            if isinstance(a, (int, float)) and isinstance(b, (int, float)):
                cheng = a * b
                if isinstance(a, (float)) or isinstance(b, (float)):
                    cheng = round(cheng, 2)  # 四舍五入,保留两位小数
            else:
                return '您是非法输入'
        except Exception as e:
            print(f'处理加法时发生了异常,异常信息是{e}')
        else:
            print('没有异常')
            return cheng
        finally:
            print('不确定是否发生了异常')


    # 除
    def myChu(self, a, b):
        try:
            if isinstance(a, (int, float)) and isinstance(b, (int, float)):
                chu = a / b
                if isinstance(a, (float)) or isinstance(b, (float)):
                    chu = round(chu, 2)  # 四舍五入,保留两位小数
            else:
                return '您是非法输入'
        except Exception as e:
            print(f'处理加法时发生了异常,异常信息是{e}')
        else:
            print('没有异常')
            return chu
        finally:
            print('不确定是否发生了异常')

if __name__ == '__main__':
    ys=DoYunSuan()
    ys.mySum(20,90)
    ys.myJian(20,90)
    ys.myCheng(2,5)
    ys.myChu(6,0)




